package svcContent

import (
	"github.com/rs/zerolog"
	"shangke-device/app/conf"
	"shangke-device/app/mqtt"
	"shangke-device/internal/log"
	ymqtt "shangke-device/internal/mqtt"
)

type SvcContent struct {
	Conf conf.Conf
	Mqtt *ymqtt.Server
	Log  *zerolog.Logger
}

func NewSvc(conf conf.Conf) *SvcContent {

	alog, err := log.NewLog(conf.DefaultLog)
	if err != nil {
		panic(err)
	}

	dlog, err := log.NewLog(conf.DeviceLog)
	if err != nil {
		panic(err)
	}

	mq, err := ymqtt.NewService(conf.MqttConf, dlog, mqtt.Subscribes)
	if err != nil {
		panic(err)
	}

	return &SvcContent{
		Conf: conf,
		Mqtt: mq,
		Log:  alog,
	}
}
